package multimedia;

import java.io.ByteArrayOutputStream;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.media.control.RecordControl;

import ui.VadeMecumCameraCanvas;

public class StartRecordThread implements Runnable, CommandListener {

	private VadeMecumCameraCanvas canvas;
	
	private ByteArrayOutputStream recordStream;
	
	public StartRecordThread(VadeMecumCameraCanvas canvas) {
		this.canvas = canvas;
	}
	
	public void run() {
		try {			
			//grab a record control
			RecordControl rc = canvas.getRecordControl();
			
			//stream to store the data recorded
			recordStream = new ByteArrayOutputStream();
			
			//set up the record stream
			rc.setRecordStream(recordStream);
			
			//start recording
			rc.startRecord();
			
			canvas.removeCommand(canvas.initRecording);
			canvas.addCommand(canvas.stopRecording);
			canvas.setRecording(true);
		} catch (Exception e) {
			canvas.midlet.error(e);
		}
		
	}

	public void commandAction(Command arg0, Displayable arg1) {
		// TODO Auto-generated method stub
		
	}	

}
